package com.lagou.homework3.two;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class WorkerTest {
    public static void main(String[] args) {
        List<Worker> lt1 = new ArrayList<>();
        lt1.add(new Worker("凤姐",18,20000));
        lt1.add(new Worker("欧阳峰",60,8000));
        lt1.add(new Worker("刘德华",40,30000));

        System.out.println("2.定义List集合，在List集合中增加三个员工，基本信息如下：  \"凤姐\" 18 20000  \"欧阳峰\" 60 8000  \"刘德华\" 40 30000 ");
        System.out.println("lt1 = " + lt1);

        System.out.println("3.在\"欧阳峰\"之前插入一个员工，信息为：姓名：\"张柏芝\"，年龄：35，工资3300");
        int pos = lt1.indexOf(new Worker("欧阳峰",60,8000));
        lt1.add(pos,new Worker("张百芝",35,35000));
        System.out.println("lt1 = " + lt1);

        System.out.println("4.删除\"刘德华\"的信息  ");
        lt1.remove(new Worker("刘德华",40,30000));
        System.out.println("lt1 = " + lt1);

        System.out.println("5.利用for 循环遍历，打印List 中所有员工的信息 ");
        int size = lt1.size();
        for (int i = 0; i < size; i++) {
            System.out.println("第" + i + "元素：" + lt1.get(i));
        }

        System.out.println("6.利用迭代遍历，对List 中所有的员工调用work 方法 ");
        Iterator<Worker> iterator = lt1.iterator();
        while (iterator.hasNext()){
            iterator.next().work();
        }

        System.out.println("为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true");
        Worker w1 = new Worker("凤姐",18,20000);
        Worker w2 = new Worker("凤姐",18,20000);
        Worker w3 = new Worker("欧阳峰",60,8000);
        System.out.println("w1 == w2 : " + w1.equals(w2));
        System.out.println("w1 == w3 : " + w1.equals(w3));
    }
}
